// 登录
export const login_api = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/login', { method: 'post', body: params })
}
export const logout_api = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/logout', { method: 'post', body: params })
}

// 查询性别
export const getSex = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getSex', { method: 'get', params: params })
}

// 查询比赛状态字典
export const getRaceStatus = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getRaceStatus', { method: 'get', params: params })
}

// 查询比赛级别字典
export const getRaceLevel = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getRaceLevel', { method: 'get', params: params })
}


// 注册
export const register_api = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/register', { method: 'post', body: params })
}
export const updateUserInfo = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/updateUserInfo', { method: 'post', body: params })
}
// 发送验证码
export const send_email = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/email/sendEmail/' + params, { method: 'post' })
}
// 获取用户信息
export const get_user_info = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/getUserInfo', { method: 'post', params: params })
}
// 获取比赛列表
export const race_list = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/race/raceList', { method: 'get', params: params })
}
// 获取比赛类型列表
export const race_type_list = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/race/typeList', { method: 'get', params: params })
}
// 赛道类型列表
export const lanqiao_type_list = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/typeList', { method: 'post', body: params })
}
// 获取比赛详情
export const race_detail = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/race/detail/' + params, { method: 'get' })
}
// 学生报名
export const student_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/student/' + params?.raceId, { method: 'post', body: params })
}
// 获取学生报名
export const get_student_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/student/' + params?.raceId, { method: 'get', params: params })
}
// 修改学生报名
export const update_student_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/student', { method: 'put', body: params })
}

// 教师报名
export const teacher_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/teacher/' + params?.raceId, { method: 'post', body: params })
}
// 获取教师报名
export const get_teacher_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/teacher/' + params?.raceId, { method: 'get', params: params })
}
// 修改教师报名
export const update_teacher_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/teacher', { method: 'put', body: params })
}
// 删除报名
export const delete_bm = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/lanqiao/${params.raceId}/${params.flag}`, { method: 'delete' })
}

// 获取职称
export const get_title = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getTitle', { method: 'get', params: params })
}
// 获取专业信息列表
export const getCollegeMajor = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/getCollegeMajor', { method: 'get', params: params })
}

// 找回密码
export const findPassword_api = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/findPassword', { method: 'POST', body: params })
}

// 获取当前登录用户
export const getLoginUser = () => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/getLoginUser', {
      method: 'get',
    });
  };

// 创建团队
export const createTeam_api = (params, raceId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/createTeam/${raceId}`, { method: 'POST', body: params });
};

// 获取师信息
export const getTeacherList_api = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/lanqiao/getTeacherList/' + params, { method: 'get' })
}

// 获取年级字典
export const getStuGrade_api = () => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getStuGrade', { method: 'get' })
}

// 获取班级字典
export const getStuClass_api = () => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getStuClass', { method: 'get' })
}

// 获取专业信息
export const getMajorList_api = () => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/user/getCollegeMajor', { method: 'get' })
}

// 根据队伍id查询队伍成员
export const getTeamMember = (teamId, params = { pageNum: 1, pageSize: 100 }) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/Member/${teamId}?pageNum=${params.pageNum}&pageSize=${params.pageSize}`, {
        method: 'get',
        params: params
    })
}

// 文件上传
export const uploadFile = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/uploads`, { method: 'post', body: params })
}

// 查询组队列表
export const getTeamList = (params) => {
    const { $myFetch } = useNuxtApp();
    const { pageNum = 1, pageSize = 8, ...restParams } = params;
    return $myFetch(`/api/team/list?pageNum=${pageNum}&pageSize=${pageSize}&isPublish=Y`, { method: 'post', body: restParams })
}

// 查询比赛类型字典
export const getRaceType = () => {
    const { $myFetch } = useNuxtApp();
    return $myFetch('/api/dict/getRaceType', { method: 'get' })
}
// 添加成员
export const addTeamMember = (params) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/addTeamMember?teamId=${params.teamId}`,
        { method: 'post', body: params.userInfoVoList })
}

// 剔除团队成员
export const deleteTeamMember = (teamId, userId, isTeacher = 0) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/deleteTeamMember/${teamId}/${userId}/${isTeacher}`, { method: 'delete' });
};
// 根据学号查询用户信息
export const getUserInfoByNumber = (number) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/user/getUserInfoByNumber?number=${number}`, { method: 'post' });
};

// 获取用户团队
export const getUserTeams = (params) => {
    const { $myFetch } = useNuxtApp();
    const { pageNum = 1, pageSize = 100, userId } = params;
    return $myFetch(`/api/team/list?pageNum=${pageNum}&pageSize=${pageSize}&userId=${userId}`, {
        method: 'post',
    });
}

//修改团队信息(招募)
export const updateUserTeams = (params, updatedData) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/update?teamId=${params.teamId}`, {
        method: 'put',
        body: updatedData
    });
}



  // 队长转让
export const transferLeader = (teamId, userId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/transfer/${teamId}/${userId}`, {
      method: 'post',
    });
  };

//提取奖状文字
export const getExtracttext = (params) => {
    const { $myFetch } = useNuxtApp();
    const { image } = params;

    // 确保 image 参数是经过编码的，以避免 URL 编码问题
    const encodedImage = encodeURIComponent(image);
    const url = `/api/ai/imageAnalysis?image=${encodedImage}`;



    return $myFetch(url, {
        method: 'post',
    });
}


// 根据团队 ID 查询团队信息
export const getTeamDetail = (id) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/${id}`, {
        method: "get",
    });
};



//申请加入
export const joinTeam = (teamData) => {
    const { $myFetch } = useNuxtApp();
    const url = '/api/team/joinTeam';
    const method = 'post';

    return $myFetch(url, {
        method,
        body: teamData // 请求体数据
    })
        .then(response => {
            // 如果响应成功，返回响应数据
            return response;
        })
        .catch(error => {
            // 如果请求失败，返回一个错误对象
            console.error('Error in joinTeam:', error);
            return { code: 500, msg: error.message || 'Internal Server Error' };
        });
};


// 查看用户参加的所有比赛
export const getAllTeam = (userId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/race/getUserRaceList`, {
        method: "get",
        params: { userId: userId }, // 将 userId 作为查询参数传递
    });
};


//获取用户所获得的奖项
export const getUserAward = (userId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/user/getUserAward`, {
        method: "get",
        params: { userId: userId }, // 将 userId 作为查询参数传递
    });
}

//预报名
export const addPre = (isTeacher, raceId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/join/addPre`, {
        method: 'POST',
        params: { isTeacher: isTeacher, raceId: raceId }
    });
};
// 退出团队
export const quitTeam = (teamId) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/team/quit/${teamId}`, { method: 'post' });
};


// 奖状审核
export const audit = (awardId, status) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/buis/records/audit?teamId=${awardId}&status=${status}`, {
        method: 'put'
    });
}

//查询老师或学生信息
export const getteachers = (isTeacher) => {
    const { $myFetch } = useNuxtApp();
    return $myFetch(`/api/getAllUser/teachers`, {
        method: "get",
        params: { isTeacher: isTeacher },
    });
}